﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/


using System.Text;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// LineChart
    /// Documentation available at http://code.google.com/intl/fr-FR/apis/visualization/documentation/gallery/linechart.html
    /// Playground : http://code.google.com/apis/ajax/playground/?type=visualization#line_chart
    /// </summary>
    public class LineChart : ChartBase
    {

        /// <summary>
        /// Gets or sets the style.
        /// </summary>
        /// <value>The style.</value>
        public LineChartStyle Style { get; set; }

        /// <summary>
        /// Gets or sets the X data.
        /// </summary>
        /// <value>The X data.</value>
        public HAxis XData { get; set; }

        /// <summary>
        /// Gets or sets the Y data.
        /// </summary>
        /// <value>The Y data.</value>
        public VAxis YData { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="LineChart"/> class.
        /// </summary>
        public LineChart()
        {
            Style = new LineChartStyle();
            XData = new HAxis();
            YData = new VAxis();

        }

        /// <summary>
        /// Hashes the key.
        /// </summary>
        /// <returns></returns>
        public string HashKey()
        {
            return BuildHashKey(GetJsOptions());
        }


        /// <summary>
        /// Gets the js options.
        /// </summary>
        /// <returns></returns>
        public string GetJsOptions()
        {
            if ((Style.ToString().Length == 0) && (XData.IsEmpty) && (YData.IsEmpty))
                return "{}";

            StringBuilder sb = new StringBuilder("{");
            if (Style.ToString().Length > 0)
                sb.Append(Style.ToString()).Append(",");

            if (!XData.IsEmpty)
                sb.Append("hAxis: {").Append(XData.ToString()).Append("},");

            if (!YData.IsEmpty)
                sb.Append("vAxis: {").Append(YData.ToString()).Append("},");

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            sb.Append("}");

            return sb.ToString();
        }
    }
}
